/*
 * Unknown.h
 *
 *  Created on: 2011-2-15
 *      Author: terry
 */

#ifndef UNKNOWN_H_
#define UNKNOWN_H_

#include "BasicType.h"

template < class T >
class TUnknown : public T
{
public:
	TUnknown() :
        m_refCount(1)
    {
    }

	HRESULT WINAPI QueryInterface( REFIID iid, void** ppvObject )
    {
        if (IID_IUnknown == iid)
	    {
		    *ppvObject = dynamic_cast<IUnknown*>( this );
	    }
        else
        {
            *ppvObject = NULL;
    		return E_NOINTERFACE;
        }
        
        AddRef();

        return S_OK;
    }

	ULONG WINAPI AddRef()
    {
        return (m_refCount ++);
    }

	ULONG WINAPI Release()
    {
        return (m_refCount --);
    }

protected:
    ULONG   m_refCount;

};


#endif /* UNKNOWN_H_ */
